# -*- coding: utf-8 -*- 
# 获取连接信息

import urllib2
from BeautifulSoup import BeautifulSoup
from urlparse import urljoin
import short_url
import logging


def get_link_info(link):
    # short_url
    name = short_url.random_shortcut()
    link = link.encode('utf-8')
    
    # open link
    page = urllib2.urlopen(link)
    soup = BeautifulSoup(page)
    
    # title
    title = soup.findAll('title')[0].getText()

    # images
    pictures = []
    images = soup.findAll('img')
    for image in images:
        try:
            src = image['src']
            pictures.append(urljoin(link, src))
        except:
            pass
    
    return name,title,pictures
